#-*- coding:utf-8 -*-
#python基本的操作
#print 语句调用str()显示对象，而交互式解释器则用repr()函数来显示
#python 不支持变量的自增
#所有非0的数都是True
print abs(-4)
print "%s is number %d!" % ("Python", 1)

mytype = 'Java'

mystr = "%s is my master language!" % mytype
print mystr
print repr(mystr)

#重定向
import sys
print >> sys.stderr, 'Fatal eroor: invalid input!'

import os
log  = open(os.curdir + "/log.txt", 'a')
print >> log, 'Fatal error: invalid input:!'

log.flush()
#name = raw_input("Enter login name:")
aList = [1,2,3,4]
print aList
print repr(aList)
print aList[0]
print aList[2:]
print aList[:3]
aList[1] = 5
print aList

aTuple = ('robots',77,93,'try')
print aTuple
print aTuple[:3]
try:
    aTuple[1] = 5
except TypeError ,msg:
    print msg

print aTuple
#代替3元判断
print 1 if 4 > 5 else 2

for i, ch in enumerate(aTuple):
    print "The index is %d, and value is %s" %(i,ch)
squared = [x ** 2 for x in range(4)]
for v in squared:
    print v

def addMe2Me(x):
    'apply + operation to argument'
    return x + x

sys.stdout.write('hello, world!\n')
sys.stdout.write(sys.platform)
sys.stdout.write('\n')
sys.stdout.write(sys.version)

